"""
归一化处理
"""
import cv2
import numpy as np

# 读取彩色图像
img = cv2.imread('/Users/linhu/IdeaProjects/yolov7/wanmu/handler/615.jpg')

# 转换成浮点型数据类型
img = img.astype(np.float32)

# 分别对BGR通道进行归一化处理
for i in range(3):
    channel = img[:, :, i]
    channel_mean = np.mean(channel)
    channel_std = np.std(channel)
    channel_normalized = (channel - channel_mean) / channel_std
    img[:, :, i] = channel_normalized

# 将像素值缩放回[0, 255]范围
img = np.clip(img, 0, 255)
img = img.astype(np.uint8)

# 保存归一化后的图像
cv2.imwrite('/Users/linhu/IdeaProjects/yolov7/wanmu/handler/example_normalized.jpg', img)
print('asdasd')
